<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>template</title>
</head>

<body>
  <script>
    // 工厂模式
    function createPerson(name) {
      let obj = {};
      obj.name = name
      obj.showName = function () {
        // console.log(this)
        return alert('工厂模式' + this.name);
      }
      return obj;

    }

    let a = createPerson('小明');
    let b = createPerson('小王');
    a.showName();
    b.showName();

    function CreatePerson(name) {
      this.name = name;
      this.showName = function () {
        console.log(this)
        return alert('构造函数' + this.name);
      }
    }

    let c = new CreatePerson('jack');
    let d = new CreatePerson('maik');

    c.showName();
    d.showName();
  </script>
</body>

</html>